<template>
  <div>
    <el-table :data="unList">
      <el-table-column
        type="index"
        width="50">
      </el-table-column>
      <el-table-column
        prop="nickname"
        label="昵称">
      </el-table-column>
      <el-table-column
        prop="remark"
        label="备注">
      </el-table-column>
      <el-table-column
        prop="do"
        label="操作">
        <template slot-scope="scope">
          <el-button type="danger" v-if="scope.row.status === 0" size="small" @click="approve(scope.row.id)">待审批</el-button>
          <el-button :disabled="true" v-if="scope.row.status === 1">已审批通过</el-button>
          <el-button type="text" @click="getDetail(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 15, 20, 25]"
        :page-size="page.pageSize"
        :current-page="page.pageNum"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'account',
  data () {
    return {
      url: {
        list: '/withdrawal/account/unaudited/list',
        approve: '/withdrawal/account/approve',
        detail: '/withdrawal/account/detail'
      },
      unList: [],
      page: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      detail: null
    }
  },
  methods: {
    initList () {
      this.$ajax.post(this.url.list, {pageNum: this.page.pageNum, pageSize: this.page.pageSize})
        .then(res => {
          if (res.data.success) {
            this.unList = res.data.data.list
            this.page.total = res.data.data.total
          }
        })
    },
    getDetail (row) {
      let params = {
        userId: row.userId,
        masterId: row.masterId,
        branchId: row.branchId
      }
      this.$ajax.post(this.url.detail, params)
        .then(res => {
          if (res.data.success) {
          }
        })
    },
    approve (id) {
      this.$confirm('确定审批通过吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = {
          accountId: id,
          isApprove: true
        }
        this.$ajax.post(this.url.approve, params)
          .then(res => {
            if (res.data.success) {
              this.$message.success('审批通过')
              this.initList()
            } else {
              this.$message.error(res.data.errorMessage)
            }
          })
      })
    },
    handleSizeChange (val) {
      this.page.pageSize = val
      this.initList()
    },
    handleCurrentChange (val) {
      this.pageNum = val
      this.initList()
    }
  },
  created () {
    this.initList()
  }
}
</script>

<style scoped>
  .page{
    float: right;
    margin-top: 16px;
  }
</style>
